home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / CDTools / GoFetch! / arexx / Neil_Bothwick / GoFetch.br next >
Text File  |  1999-12-12  |  4KB  |  133 lines

  1. /*
  2.     $VER: GoFetch.br 1.0 (11.12.99)
  3.     by Neil Bothwick
  4.  
  5.     GoFetch.br will transfer files selected for download in THOR
  6.     from the Events editor to the GoFetch! profiles list.
  7.  
  8.     Usage: GoFetch.br SystemName/A
  9.  
  10.     If you want to do the transfer from within THOR, run GoFetch.thor
  11.     from the Arexx menu or as the system Exit command.
  12.     GoFetch.thor simply determines the current system name and passes
  13.     it to GeFetch.br.
  14.  
  15.     Installation involves copying both scripts to Thor/rexx, editing
  16.     the GFPath variable to point to your copy of GoFetch! and setting
  17.     FetchReadme to 1 if you want GoFetch! to get the Aminet readme files too
  18. */
  19.  
  20. GFPath       = 'GoFetch:GoFetch!'   /* Edit this, this would be unnecessary if GoFetch! used an assign or env var */
  21. FetchReadme  = 0                    /* Set this to 1 if you want the Aminet readmes */
  22. AminetServer = 'de.aminet.net'      /* You can set this to use one of the Aminet mirrors instead of the main site */
  23.  
  24. /* Do not change anything below here */
  25. parse arg System
  26.  
  27. /* Event types */
  28. EVE_DOWNLOAD     =  4               /* Download file */
  29. EVE_UPLOAD       =  5               /* Upload file */
  30.  
  31. /* Event flags */
  32. EDF_DELETED       = '00000001'x     /* Event is deleted */
  33. EDF_DONE          = '00000004'x     /* Event is done */
  34. EDF_ERROR         = '00000008'x     /* Error performing this event */
  35.  
  36. CompMask = bitor(EDF_DELETED,EDF_DONE)
  37.  
  38. /* Make sure bbsread.library and GoFetch! are open */
  39. options results
  40. if ~show('p', 'BBSREAD') then do
  41.     address command
  42.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  43.     'WaitForPort BBSREAD'
  44.     end
  45.  
  46. if ~show('P','GOFETCH') then do
  47.     ProgStart = 1
  48.     address command
  49.     'run >NIL:' GFPath
  50.     'waitforport GOFETCH'
  51.     address 'GOFETCH' 'iconify'
  52.     end
  53.  
  54.  
  55. /* Build list of download events */
  56. address 'BBSREAD'
  57. GETBBSDATA System SystemData
  58. FirstEvent = SystemData.FIRSTEVENT
  59. LastEvent  = SystemData.LASTEVENT
  60.  
  61. Count = 0
  62. drop DLEvent.
  63. do EventNo = FirstEvent to LastEvent
  64.     drop EventData. EventTags.
  65.     READBREVENT '"'System'"' eventnr EventNo datastem EventData tagsstem EventTags
  66.     if RC > 0 then ExitMsg(BBSREAD.LASTERROR)
  67.     if (EventData.EVENTTYPE = EVE_DOWNLOAD) & (c2d(bitand(EventData.FLAGS,CompMask)) = 0) then do
  68.         Count = Count + 1
  69.         DLEvent.Count.No = EventNo
  70.         DLEvent.Count.Dir  = EventTags.DIRECTORY
  71.         DLEvent.Count.File = EventTags.FILENAME
  72.         end
  73.     end
  74.  
  75. if Count = 0 then exit
  76.  
  77. /* Create new download events */
  78. address 'GOFETCH'
  79. 'getanon'
  80. AnonPass = result
  81. 'getdownloadpath'
  82. DownloadDir = result
  83. drop AddFail.
  84.  
  85. do i = 1 to Count
  86.     ThisDir = DLEvent.i.Dir
  87.     ThisFile = DLEvent.i.File
  88.     Readme = left(ThisFile,lastpos('.',ThisFile))||'readme'
  89.     if upper(left(ThisFile,6)) = 'FTP://' then do
  90.         parse var ThisFile . '://' Server '/' Path
  91.         ThisDir = PathPart(Path)
  92.         ThisFile = FilePart(Path)
  93.         end
  94.     else do
  95.         Server = AminetServer
  96.         ThisDir = AddPart('pub/aminet',ThisDir)
  97.         end
  98.  
  99.     AddFail.i = 0
  100.     if FetchReadme > 0 then do
  101.         'addanonprofile site' server 'port 21 remotepath' ThisDir 'filename' Readme   'localpath' DownloadDir
  102.         AddFail.i = AddFail.i + RC
  103.         end
  104.     'addanonprofile site' server 'port 21 remotepath' ThisDir 'filename' ThisFile 'localpath' DownloadDir
  105.     AddFail.i = AddFail.i + RC
  106.     end
  107.  
  108. if ProgStart = 1 then 'quitgofetch'
  109.  
  110. /* Mark original download events as deleted */
  111. address 'BBSREAD'
  112. do i = 1 to Count
  113.     if AddFail.i = 0 then do
  114.         UPDATEBREVENT '"'System'"' DLEvent.i.No SETDELETED
  115.         if RC > 0 then ExitMsg(BBSREAD.LASTERROR)
  116.         end
  117.     end
  118.  
  119. /* Clear events list if possible */
  120. PACKDATAFILE '"'System'"' EVENTDATA
  121. if RC > 0 then ExitMsg(BBSREAD.LASTERROR)
  122.  
  123.  
  124. exit
  125.  
  126. ExitMsg:
  127.     parse arg msg
  128.     say
  129.     say msg
  130.     say
  131.     exit
  132.  
  133.